home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / c01lab4.zip / LRMRDR / LRM_CHAP.ZIP / CHAP13.DOC < prev    next >
Text File  |  1992-04-21  |  48KB  |  1,139 lines

  1. >      13. Representation Clauses and Implementation-Dependent Features
  2.  
  3.  
  4. This      chapter     describes     representation     clauses,     certain
  5. implementation-dependent features, and other  features  that  are  used  in
  6. system programming.
  7.  
  8. > 13.1  Representation Clauses
  9.  
  10.  
  11. Representation  clauses  specify  how  the  types of the language are to be
  12. mapped onto the underlying machine.  They can  be  provided  to  give  more
  13. efficient representation or to interface with features that are outside the
  14. domain of the language (for example, peripheral hardware).
  15.  
  16.  
  17.     representation_clause ::=
  18.          type_representation_clause | address_clause
  19.  
  20.     type_representation_clause ::= length_clause
  21.        | enumeration_representation_clause | record_representation_clause
  22.  
  23.  
  24. A  type  representation clause applies either to a type or to a first named
  25. subtype (that is, to a subtype declared by a  type  declaration,  the  base
  26. type  being  therefore anonymous).  Such a representation clause applies to
  27. all objects that have this type or this first named subtype.  At  most  one
  28. enumeration  or  record  representation clause is allowed for a given type:
  29. an enumeration representation clause is only  allowed  for  an  enumeration
  30. type;   a  record  representation  clause, only for a record type.  (On the
  31. other hand, more than one length clause can be provided for a  given  type;
  32. moreover,  both a length clause and an enumeration or record representation
  33. clause  can  be  provided.)   A  length  clause  is  the   only   form   of
  34. representation  clause  allowed  for a type derived from a parent type that
  35. has (user-defined) derivable subprograms.
  36.  
  37.  
  38. An address clause applies either to an object;  to a  subprogram,  package,
  39. or  task  unit;  or to an entry.  At most one address clause is allowed for
  40. any of these entities.
  41.  
  42.  
  43. A representation clause and the declaration of  the  entity  to  which  the
  44. clause  applies  must  both  occur  immediately within the same declarative
  45. part, package specification, or task specification;  the  declaration  must
  46. occur  before  the clause.  In the absence of a representation clause for a
  47. given  declaration,  a  default  representation  of  this  declaration   is
  48. determined  by  the implementation.  Such a default determination occurs no
  49. later than the end of the immediately enclosing declarative  part,  package
  50. specification,  or  task  specification.   For  a  declaration  given  in a
  51. declarative part, this default determination  occurs  before  any  enclosed
  52. body.
  53.  
  54.  
  55. In  the  case  of  a  type,  certain occurrences of its name imply that the
  56. representation of the type must already have been determined.  Consequently
  57. these occurrences force the default determination  of  any  aspect  of  the
  58. representation  not  already  determined  by  a  prior  type representation
  59. clause.  This default determination is also forced by  similar  occurrences
  60. of the name of a subtype of the type, or of the name of any type or subtype
  61. that has subcomponents of the type.  A forcing occurrence is any occurrence
  62. other than in a type or subtype declaration, a subprogram specification, an
  63. entry  declaration,  a  deferred  constant  declaration,  a  pragma,  or  a
  64. representation clause for the type itself.   In  any  case,  an  occurrence
  65. within an expression is always forcing.
  66.  
  67.  
  68. A  representation  clause  for  a  given  entity  must  not appear after an
  69. occurrence of the name of the entity if this occurrence  forces  a  default
  70. determination of representation for the entity.
  71.  
  72.  
  73. Similar  restrictions  exist  for  address  clauses.   For  an  object, any
  74. occurrence of  its  name  (after  the  object  declaration)  is  a  forcing
  75. occurrence.  For a subprogram, package, task unit, or entry, any occurrence
  76. of a representation attribute of such an entity is a forcing occurrence.
  77.  
  78.  
  79. The  effect  of the elaboration of a representation clause is to define the
  80. corresponding aspects of the representation.
  81.  
  82.  
  83. The interpretation of some of the expressions that appear in representation
  84. clauses is implementation-dependent, for  example,  expressions  specifying
  85. addresses.   An  implementation  may limit its acceptance of representation
  86. clauses to those that can be handled simply by the underlying hardware.  If
  87. a representation clause is accepted by an implementation, the compiler must
  88. guarantee that the net effect of the program is not changed by the presence
  89. of the clause, except for address clauses and for parts of the program that
  90. interrogate  representation  attributes.    If   a   program   contains   a
  91. representation  clause  that  is not accepted, the program is illegal.  For
  92. each  implementation,  the  allowed   representation   clauses,   and   the
  93. conventions   used   for   implementation-dependent  expressions,  must  be
  94. documented in Appendix F of the reference manual.
  95.  
  96.  
  97. Whereas a representation clause is used to impose  certain  characteristics
  98. of  the  mapping   of an entity onto the underlying machine, pragmas can be
  99. used to provide an implementation with criteria for its selection of such a
  100. mapping.  The pragma PACK specifies that storage minimization should be the
  101. main criterion when selecting the representation of a record or array type.
  102. Its form is as follows:
  103.  
  104.     pragma PACK(type_simple_name);
  105.  
  106.  
  107. Packing means that gaps between the storage areas allocated to  consecutive
  108. components  should  be minimized.  It need not, however, affect the mapping
  109. of each component onto storage.  This mapping can itself be influenced by a
  110. pragma (or controlled by a representation  clause)  for  the  component  or
  111. component type.  The position of a PACK pragma, and the restrictions on the
  112. named  type, are governed by the same rules as for a representation clause;
  113. in particular, the pragma must appear before any use  of  a  representation
  114. attribute of the packed entity.
  115.  
  116.  
  117. The  pragma  PACK  is  the  only  language-defined  representation  pragma.
  118. Additional representation pragmas may be  provided  by  an  implementation;
  119. these  must  be  documented  in Appendix F.  (In contrast to representation
  120. clauses, a pragma that is not accepted by the implementation  is  ignored.)
  121.  
  122. Note:
  123.  
  124.  
  125. No representation clause is allowed for a generic formal type.
  126.  
  127.  
  128. References:   address  clause  13.5,  allow  1.6,  body 3.9, component 3.3,
  129. declaration 3.1, declarative part 3.9, default expression  3.2.1,  deferred
  130. constant  declaration  7.4,  derivable  subprogram  3.4,  derived type 3.4,
  131. entity 3.1, entry 9.5, enumeration representation clause  13.3,  expression
  132. 4.4, generic formal type 12.1.2, illegal 1.6, length clause 13.2, must 1.6,
  133. name  4.1,  object  3.2,  occur  immediately within 8.1, package 7, package
  134. specification 7.1, parent  type  3.4,  pragma  2.8,  record  representation
  135. clause  13.4,  representation  attribute  13.7.2  13.7.3, subcomponent 3.3,
  136. subprogram 6, subtype 3.3, subtype declaration  3.3.2,  task  specification
  137. 9.1, task unit 9, type 3.3, type declaration 3.3.1
  138.  
  139. > 13.2  Length Clauses
  140.  
  141.  
  142. A length clause specifies an amount of storage associated with a type.
  143.  
  144.  
  145.     length_clause ::= for attribute use simple_expression;
  146.  
  147.  
  148. The  expression  must  be  of some numeric type and is evaluated during the
  149. elaboration of the length clause (unless it is a static  expression).   The
  150. prefix of the attribute must denote either a type or a first named subtype.
  151. The  prefix  is  called  T  in  what  follows.   The only allowed attribute
  152. designators in a length clause are  SIZE,  STORAGE_SIZE,  and  SMALL.   The
  153. effect of the length clause depends on the attribute designator:
  154.  
  155.  
  156. (a)  Size specification:  T'SIZE
  157.  
  158.  
  159.      The  expression must be a static expression of some integer type.  The
  160.      value of the expression specifies an upper bound  for  the  number  of
  161.      bits  to be allocated to objects of the type or first named subtype T.
  162.      The  size  specification  must  allow  for  enough  storage  space  to
  163.      accommodate   every   allowable   value  of  these  objects.   A  size
  164.      specification for a composite type m